<template>
    <div>
        房间号<input type="text" v-model="cs.name">——<input type="date" v-model="cs.timea">-
        <input type="date" v-model="cs.timeb"><input type="button" value="查找房间" @click="show">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房间号</td>
                    <td>图片</td>
                    <td>可住人数</td>
                    <td>房间类型</td>
                    <td>备注</td>
                    <td>离店时间</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="a in as.row" :key="a.id">
                    <td>{{ a.name }}</td>
                    <td><img :src="a.img" width="70" height="70"></td>
                    <td>{{ a.address }}</td>
                    <td>{{ a.sname }}</td>
                    <td>{{ a.yao }}</td>
                    <td>{{ a.time1 }}</td>
                    <td>{{ a.tyle == true ? "已入住" : "未入住" }}</td>
                    <td>
                        <button @click="up(a.id)">{{ a.tyle == true ? "未入住" : "已入住" }}</button>
                        <input type="button" value="删除" @click="del(a.id)">
                        <input type="button" value="修改" @click="update(a.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div>
        <span>当前{{ cs.pagesize }}页</span>--
        <span>共{{ as.pagecount }}条</span>--
        <span>当前{{ cs.pageindex }}/{{ as.sizecount }}页</span>
        <input type="button" value="首页" @click="fy(1)">
        <input type="button" value="上一页" @click="fy(cs.pageindex - 1)">
        <input type="button" value="下一页" @click="fy(cs.pageindex + 1)">
        <input type="button" value="尾页" @click="fy(as.sizecount)">
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from "vue";
import moment from 'moment';
import { useStore } from '@/stores/kll';
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
const a = useStore();

let cs: any = reactive(
    {
        pageindex: '1',
        pagesize: '2',
        name: '',
        timea: '',
        timeb: ''
    }
)
let as: any = reactive(
    {
        pagecount: 0,
        sizecount: 0,
        row: []
    }
)

const fy = (f: any) => {
    if (f < 1) {
        cs.pageindex = 1;
        return;
    }
    if (f > as.sizecount) {
        cs.pageindex = as.sizecount;
        return;
    }
    cs.pageindex=f;
    show();
}
onMounted(() => {
    if(a.info.id)
{
    show();
}
else{
    router.push("/Login");
}

})

const show = () => {
    axios({
        url: 'https://localhost:7207/api/Emp/Show',
        method: 'get',
        params: cs
    })
        .then(res => {
            console.log(res);
            as.pagecount = res.data.pagecount;
            as.sizecount = res.data.sizecount;
            as.row = res.data.row;
        })
        .catch(err => {
            console.log(err);

        })
}
const up = (id: any) => {
    let f = confirm("确认修改吗");
    if (f) {
        axios({
            url: 'https://localhost:7207/api/Emp/up',
            method: 'post',
            params: {
                id: id
            }
        })
            .then(res => {
                console.log(res);
                alert("修改成功");
                show();
            })
            .catch(err => {
                console.log(err);

            })
    }

}
const del = (id: any) => {
    let f = confirm("确认删除吗");
    if (f) {
        axios({
            url: 'https://localhost:7207/api/Emp/del',
            method: 'post',
            params: {
                id: id
            }
        })
            .then(res => {
                console.log(res);
                alert("删除成功");
                show();
            })
            .catch(err => {
                console.log(err);

            })
    }
}
const update = (id: any) => {
   router.push({
    path:'/Xiu',
    query:{
        id:id
    }
   })
}
</script>

<style scoped></style>